/*=============================================================================

  APPLICATION MANAGER APPLICATION MODULE

  FILE: SYSmgr_AppOP.cpp
  
  DESCRIPTION

    Application manager Application Operation Module Definition

  EXTERNALIZED FUNCTIONS

    
  Copyright (c) DaeSung Engineering Inc. All rights reserved.

=============================================================================*/
/*=============================================================================

                             EDIT HISTORY

  ---------  -------  -------------------------------------------------------
    when       who     what, where, why
  ---------  -------  -------------------------------------------------------
   06/28/03   nso4th   Version 0.1

=============================================================================*/

/*=============================================================================
  HEADER INCLUSION
=============================================================================*/
#include <SYSmgr.h>

/*=============================================================================
  LOCALIZED FUNCTION DEFINITION
=============================================================================*/
static dword cam_eventCB(dword evt, dword wp, dword lp, mcxt pUsrCxt);

/*=============================================================================
  EXTERNALIZED FUNCTION DEFINITION
=============================================================================*/
void SYSmgr::MOD_Alloc(void)
{
	ObjClient_s	c;

	c.EventCbf = cam_eventCB;
	c.pUserCxt = this;
	
	m_areaMod = area_alloc(&c);
	m_areaInit = FALSE;
}

void SYSmgr::MOD_Free(void)
{
	if(m_areaMod == NULL)
		return;

	area_free(m_areaMod);
	m_areaMod = NULL;
}

boolean SYSmgr::MOD_Init(void)
{	
	SYSmgr_cfg_s			*cfg = CFG_Ptr();
	char					*str;

	if(cfg == NULL)
		return	FALSE;

	str = UIstring(NULL);
	
	Event_Pass(AREA_MOD, INIT_START_E, 0, 0);

	if(m_areaInit == TRUE)
	{
		UIstring(str);
		Event_Handler(AREA_MOD, INIT_DONE_E, 0, 0);
		return	TRUE;
	}
	
	// Initialize the device
	area_cfg_set(m_areaMod, &cfg->area_cfg);

	sprintf(str, "%s", cfg->area_cfg.img_path);
	//FileOp_CreateDirectory(str);
	
	if(area_init(m_areaMod))
	{
		UIstring(str);
		m_areaInit = TRUE;
		Event_Handler(AREA_MOD, INIT_DONE_E, 0, 0);
		return	TRUE;
	}

	UIstring(str);
	Event_Pass(AREA_MOD, ERR_INIT_E, 0, 0);
	
	return	FALSE;
}

boolean SYSmgr::MOD_Close(void)
{
	Event_Handler(AREA_MOD, CLOSE_START_E, 0, 0);

	if(m_areaInit == FALSE)
	{
		Event_Handler(AREA_MOD, CLOSE_DONE_E, 0, 0);
		return	TRUE;
	}

	if(area_close(m_areaMod) == TRUE)
	{
		m_areaInit = FALSE;
		Event_Handler(AREA_MOD, CLOSE_DONE_E, 0, 0);
		return	TRUE;
	}

	m_areaInit = FALSE;
	Event_Handler(AREA_MOD, ERR_CLOSE_E, 0, 0);

	return	FALSE;
}

/*=============================================================================
  LOCALIZED FUNCTION IMPLEMENTATION
=============================================================================*/
dword cam_eventCB(dword evt, dword wp, dword lp, mcxt pUsrCxt)
{
	SYSmgr		*sm = (SYSmgr*)pUsrCxt;

	if(sm == NULL)
		return	(0);

	sm->HEvent_Handler(AREA_MOD, evt, wp, lp);

	return	(1);
}

/*--- END OF SYSmgr_Mod.CPP ---*/
